#!/usr/bin/python3
# Version = 3.6.8
# -*- coding:utf-8 -*-

import sys

if __name__ == '__main__':
    if len(sys.argv) != 4:
        print(
            'usage: python filt.py [in_file_name] [match_str] [out_file_name]')

    in_file_name = sys.argv[1]
    match_str = sys.argv[2]
    out_file_name = sys.argv[3]

    last_part = []

    out_file = open(out_file_name, "w")

    find = False
    for line in open(in_file_name):
        if line[0] != '[':
            last_part.append(line)
        else:
            for s in last_part:
                if s.find(match_str) >= 0:
                    find = True
                    break
            if find:
                out_file.writelines(last_part)
            last_part = []
            find = False
            last_part.append(line)
    out_file.close()
